package genedit.aStar;

import genedit.model.graph.BreakPoint;

import java.util.ArrayList;
import java.util.List;

/**
 * Klasa enkapsulira listu prelomnih tačaka veze dobijene pretragom prostora.
 * 
 * @author Igić
 * @version 1.1 12/12/13
 */
public class Path {

	/**
	 * Lista prelomnih tačaka.
	 */
	private ArrayList<BreakPoint> breakpoints = new ArrayList<BreakPoint>();

	public Path() {
	}

	public int getLength() {
		return breakpoints.size();
	}

	public BreakPoint getBreakPoint(int index) {
		return breakpoints.get(index);
	}

	public double getX(int index) {
		return getBreakPoint(index).getPosition().getX();
	}

	public double getY(int index) {
		return getBreakPoint(index).getPosition().getY();
	}

	/**
	 * Metoda dodaje prelomnu tačku na kraj liste.
	 * 
	 * @param n
	 *            prelomna tačka koja se dodaje
	 */
	public void appendBreakPoint(BreakPoint n) {
		breakpoints.add(n);
	}

	/**
	 * Metoda dodaje prelomnu tačku na početak liste.
	 * 
	 * @param n
	 *            prelomna tačka koja se dodaje
	 */
	public void prependBreakPoint(BreakPoint n) {
		breakpoints.add(0, n);
	}

	public boolean contains(double x, double y) {
		for (BreakPoint node : breakpoints) {
			if (node.getPosition().getX() == x && node.getPosition().getY() == y)
				return true;
		}
		return false;
	}

	public List<BreakPoint> getBreakPoints() {
		if (breakpoints == null)
			breakpoints = new java.util.ArrayList<BreakPoint>();
		return breakpoints;
	}

}
